<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Docker | VanKa</title><script src="https://cdn.bootcss.com/valine/1.4.4/Valine.min.js"></script><link rel="stylesheet" href="/vcb/css/arknights.css"><link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/highlight.js/10.1.2/styles/atom-one-dark-reasonable.min.css"><style>@font-face {
 font-family: BenderLight;
 src: local('Bender'), url("/vcb/font/BenderLight.ttf");
}
@font-face {
 font-family: 'JetBrains Mono';
 src: local('JetBrains Mono'), url('/vcb/font/JetBrainsMono-Regular.woff2') format('woff2');
}</style><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/vcb/atom.xml" title="VanKa" type="application/atom+xml">
</head><body><header><nav><a href="/vcb/">Home</a><a href="/vcb/archives/">Archives</a></nav></header><main><article><div id="post-bg"><div id="post-title"><h1>Docker</h1><hr></div><div id="post-content"><h1 id="Docker概述"><a href="#Docker概述" class="headerlink" title="Docker概述"></a>Docker概述</h1><blockquote>
<p>Docker 是一个开源的应用容器引擎，基于 Go 语言 并遵从 Apache2.0 协议开源。<br>Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级、可移植的容器中，然后发布到任何流行的 Linux 机器上，也可以实现虚拟化。<br>容器是完全使用沙箱机制，相互之间不会有任何接口（类似 iPhone 的 app）,更重要的是容器性能开销极低。—–<a target="_blank" rel="noopener" href="https://www.runoob.com/docker/docker-tutorial.html">菜鸟教程</a></p>
</blockquote>
<h3 id="Docker安装"><a href="#Docker安装" class="headerlink" title="Docker安装"></a>Docker安装</h3><p><a target="_blank" rel="noopener" href="https://docs.docker.com/">官网文档</a></p>
<h4 id="Debian版本"><a href="#Debian版本" class="headerlink" title="Debian版本"></a>Debian版本</h4><p>将已安装的软件包更新到最新版本</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">apt update</span><br><span class="line">apt upgrade</span><br></pre></td></tr></table></figure>
<p>安装 mysql(Arm64v8)</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull ibex/debian-mysql-server-5.7</span><br></pre></td></tr></table></figure>
<h4 id="Windows版本"><a href="#Windows版本" class="headerlink" title="Windows版本"></a><a target="_blank" rel="noopener" href="https://blog.csdn.net/zzq060143/article/details/91050272">Windows版本</a></h4><h5 id="环境准备"><a href="#环境准备" class="headerlink" title="环境准备"></a><a target="_blank" rel="noopener" href="https://docs.docker.com/desktop/windows/install/">环境准备</a></h5><p>Docker for Windows是一个Docker Community Edition（CE）应用程序。Docker for Windows安装包包含了在Windows系统上运行Docker所需的一切。如果你不想装虚拟机，想直接在你的Windows操作系统中安装与学习使用docker，那么你首先得查看你的系统是否满足Docker for Windows的安装与使用要求。</p>
<ol>
<li><p>Docker for Windows的当前版本运行在64位Windows 10 Pro，专业版、企业版和教育版（1607年纪念更新，版本14393或更高版本）上。</p>
<p> Ps:家庭版是不行的，如果你是家庭版，那么<br> 一是升级到专业版，破解专业版推荐个地址：<a target="_blank" rel="noopener" href="http://blog.csdn.net/SONGCHUNHONG/article/details/78006389">http://blog.csdn.net/SONGCHUNHONG/article/details/78006389</a><br> 二是安装Docker Toolbox，自行网上百度<a target="_blank" rel="noopener" href="http://blog.csdn.net/tina_ttl/article/details/51372604">http://blog.csdn.net/tina_ttl/article/details/51372604</a></p>
</li>
</ol>
<h4 id="Linux版本"><a href="#Linux版本" class="headerlink" title="Linux版本"></a><a target="_blank" rel="noopener" href="https://blog.csdn.net/zzq060143/article/details/91050272">Linux版本</a></h4><h5 id="环境查看"><a href="#环境查看" class="headerlink" title="环境查看"></a>环境查看</h5><ol>
<li>查看系统内核<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">uname -r</span><br><span class="line">#3.10.0-1160.36.2.el7.x86_64 3.0以上</span><br></pre></td></tr></table></figure></li>
<li>系统版本<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">cat /etc/os-release </span><br><span class="line"></span><br><span class="line">NAME=&quot;CentOS Linux&quot;</span><br><span class="line">VERSION=&quot;7 (Core)&quot;</span><br><span class="line">ID=&quot;centos&quot;</span><br><span class="line">ID_LIKE=&quot;rhel fedora&quot;</span><br><span class="line">VERSION_ID=&quot;7&quot;</span><br><span class="line">PRETTY_NAME=&quot;CentOS Linux 7 (Core)&quot;</span><br><span class="line">ANSI_COLOR=&quot;0;31&quot;</span><br><span class="line">CPE_NAME=&quot;cpe:/o:centos:centos:7&quot;</span><br><span class="line">HOME_URL=&quot;https://www.centos.org/&quot;</span><br><span class="line">BUG_REPORT_URL=&quot;https://bugs.centos.org/&quot;</span><br><span class="line"></span><br><span class="line">CENTOS_MANTISBT_PROJECT=&quot;CentOS-7&quot;</span><br><span class="line">CENTOS_MANTISBT_PROJECT_VERSION=&quot;7&quot;</span><br><span class="line">REDHAT_SUPPORT_PRODUCT=&quot;centos&quot;</span><br><span class="line">REDHAT_SUPPORT_PRODUCT_VERSION=&quot;7&quot;</span><br></pre></td></tr></table></figure>
<h5 id="卸载旧版本"><a href="#卸载旧版本" class="headerlink" title="卸载旧版本"></a>卸载旧版本</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">yum remove docker \</span><br><span class="line">                  docker-client \</span><br><span class="line">                  docker-client-latest \</span><br><span class="line">                  docker-common \</span><br><span class="line">                  docker-latest \</span><br><span class="line">                  docker-latest-logrotate \</span><br><span class="line">                  docker-logrotate \</span><br><span class="line">                  docker-engine</span><br></pre></td></tr></table></figure></li>
</ol>
<h5 id="下载安装包"><a href="#下载安装包" class="headerlink" title="下载安装包"></a>下载安装包</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install -y yum-utils</span><br></pre></td></tr></table></figure>
<h5 id="设置镜像仓库"><a href="#设置镜像仓库" class="headerlink" title="设置镜像仓库"></a>设置镜像仓库</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">yum-config-manager \</span><br><span class="line">    --add-repo \</span><br><span class="line">	http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #阿里云</span><br><span class="line">	https://download.docker.com/linux/centos/docker-ce.repo #默认国外的</span><br></pre></td></tr></table></figure>
<h5 id="更新yum软件包索引"><a href="#更新yum软件包索引" class="headerlink" title="更新yum软件包索引"></a>更新yum软件包索引</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum makecache fast</span><br></pre></td></tr></table></figure>
<h5 id="安装-Docker-引擎"><a href="#安装-Docker-引擎" class="headerlink" title="安装 Docker 引擎"></a>安装 Docker 引擎</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yum install docker-ce docker-ce-cli containerd.io # docker-ce 社区版  docker-ee 企业版</span><br></pre></td></tr></table></figure>
<h5 id="启动-Docker"><a href="#启动-Docker" class="headerlink" title="启动 Docker"></a>启动 Docker</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl start docker </span><br></pre></td></tr></table></figure>
<h5 id="设置开机自启"><a href="#设置开机自启" class="headerlink" title="设置开机自启"></a>设置开机自启</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">systemctl enable docker</span><br></pre></td></tr></table></figure>

<h5 id="查看-Docker-版本"><a href="#查看-Docker-版本" class="headerlink" title="查看 Docker 版本"></a>查看 Docker 版本</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker version</span><br></pre></td></tr></table></figure>

<ol>
<li><p>Linux</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">Client: Docker Engine - Community</span><br><span class="line"> Version:           20.10.8</span><br><span class="line"> API version:       1.41</span><br><span class="line"> Go version:        go1.16.6</span><br><span class="line"> Git commit:        3967b7d</span><br><span class="line"> Built:             Fri Jul 30 19:53:39 2021</span><br><span class="line"> OS/Arch:           linux/amd64</span><br><span class="line"> Context:           default</span><br><span class="line"> Experimental:      true</span><br><span class="line"></span><br><span class="line">Server: Docker Engine - Community</span><br><span class="line"> Engine:</span><br><span class="line">  Version:          20.10.8</span><br><span class="line">  API version:      1.41 (minimum version 1.12)</span><br><span class="line">  Go version:       go1.16.6</span><br><span class="line">  Git commit:       75249d8</span><br><span class="line">  Built:            Fri Jul 30 19:52:00 2021</span><br><span class="line">  OS/Arch:          linux/amd64</span><br><span class="line">  Experimental:     false</span><br><span class="line"> containerd:</span><br><span class="line">  Version:          1.4.9</span><br><span class="line">  GitCommit:        e25210fe30a0a703442421b0f60afac609f950a3</span><br><span class="line"> runc:</span><br><span class="line">  Version:          1.0.1</span><br><span class="line">  GitCommit:        v1.0.1-0-g4144b63</span><br><span class="line"> docker-init:</span><br><span class="line">  Version:          0.19.0</span><br><span class="line">  GitCommit:        de40ad0</span><br></pre></td></tr></table></figure></li>
<li><p>DeBian</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">Client: Docker Engine - Community</span><br><span class="line"> Version:           20.10.8</span><br><span class="line"> API version:       1.41</span><br><span class="line"> Go version:        go1.16.6</span><br><span class="line"> Git commit:        3967b7d</span><br><span class="line"> Built:             Fri Jul 30 19:55:49 2021</span><br><span class="line"> OS/Arch:           linux/amd64</span><br><span class="line"> Context:           default</span><br><span class="line"> Experimental:      true</span><br><span class="line"></span><br><span class="line">Server: Docker Engine - Community</span><br><span class="line"> Engine:</span><br><span class="line">  Version:          20.10.8</span><br><span class="line">  API version:      1.41 (minimum version 1.12)</span><br><span class="line">  Go version:       go1.16.6</span><br><span class="line">  Git commit:       75249d8</span><br><span class="line">  Built:            Fri Jul 30 19:54:13 2021</span><br><span class="line">  OS/Arch:          linux/amd64</span><br><span class="line">  Experimental:     false</span><br><span class="line"> containerd:</span><br><span class="line">  Version:          1.4.9</span><br><span class="line">  GitCommit:        e25210fe30a0a703442421b0f60afac609f950a3</span><br><span class="line"> runc:</span><br><span class="line">  Version:          1.0.1</span><br><span class="line">  GitCommit:        v1.0.1-0-g4144b63</span><br><span class="line"> docker-init:</span><br><span class="line">  Version:          0.19.0</span><br><span class="line">  GitCommit:        de40ad0</span><br></pre></td></tr></table></figure></li>
</ol>
<h5 id="查看-Docker-系统信息"><a href="#查看-Docker-系统信息" class="headerlink" title="查看 Docker 系统信息"></a>查看 Docker 系统信息</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker info</span><br></pre></td></tr></table></figure>
<h5 id="Docker-帮助命令"><a href="#Docker-帮助命令" class="headerlink" title="Docker 帮助命令"></a>Docker 帮助命令</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker --help</span><br></pre></td></tr></table></figure>

<h5 id="测试"><a href="#测试" class="headerlink" title="测试"></a>测试</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run hello-world                                                           # 启动 hello-world</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Unable to find image &#x27;hello-world:latest&#x27; locally                                # 没有找到镜像文件</span><br><span class="line">latest: Pulling from library/hello-world                                         # 远程拉取镜像</span><br><span class="line">b8dfde127a29: Pull complete </span><br><span class="line">Digest: sha256:0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38</span><br><span class="line">Status: Downloaded newer image for hello-world:latest</span><br><span class="line">Hello from Docker!                                                               # 启动成功</span><br><span class="line">This message shows that your installation appears to be working correctly.</span><br></pre></td></tr></table></figure>
<h5 id="卸载-Docker-引擎"><a href="#卸载-Docker-引擎" class="headerlink" title="卸载 Docker 引擎"></a>卸载 Docker 引擎</h5><p>卸载 Docker Engine、CLI 和 Containerd 包：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sudo yum remove docker-ce docker-ce-cli containerd.io</span><br></pre></td></tr></table></figure>
<p>主机上的映像、容器、卷或自定义配置文件不会自动删除。删除所有镜像、容器和卷：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">sudo rm -rf /var/lib/docker</span><br><span class="line">sudo rm -rf /var/lib/containerd</span><br></pre></td></tr></table></figure>
<p>您必须手动删除任何已编辑的配置文件。</p>
<h5 id="配置阿里云-容器镜像加速器"><a href="#配置阿里云-容器镜像加速器" class="headerlink" title="配置阿里云 容器镜像加速器"></a>配置阿里云 容器镜像加速器</h5><p>阿里云-》弹性计算-》镜像加速器</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">sudo mkdir -p /etc/docker                                      # 创建目录</span><br><span class="line"></span><br><span class="line">sudo tee /etc/docker/daemon.json &lt;&lt;-&#x27;EOF&#x27;                      # 编辑文件</span><br><span class="line">sudo tee /etc/docker/daemon.json &lt;&lt;-&#x27;EOF&#x27;                      </span><br><span class="line">&#123;</span><br><span class="line">  &quot;registry-mirrors&quot;: [&quot;https://7kr9hm9h.mirror.aliyuncs.com&quot;]</span><br><span class="line">&#125;</span><br><span class="line">EOF</span><br><span class="line">sudo systemctl daemon-reload                                   # 暂停服务</span><br><span class="line">sudo systemctl restart docker                                  # 启动服务</span><br></pre></td></tr></table></figure>

<h5 id="docker-流程"><a href="#docker-流程" class="headerlink" title="docker 流程"></a>docker 流程</h5><p> 开始-&gt; docker会在本机中寻找images（找到镜像 启用）-&gt; 未找到 -&gt; 去DockerHub下载镜像</p>
<h3 id="Docker-命令"><a href="#Docker-命令" class="headerlink" title="Docker 命令"></a>Docker 命令</h3><h4 id="镜像命令"><a href="#镜像命令" class="headerlink" title="镜像命令"></a>镜像命令</h4><h5 id="查看镜像文件"><a href="#查看镜像文件" class="headerlink" title="查看镜像文件"></a>查看镜像文件</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker images</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">REPOSITORY    TAG       IMAGE ID       CREATED        SIZE</span><br><span class="line">hello-world   latest    d1165f221234   5 months ago   13.3kB</span><br></pre></td></tr></table></figure>
<h5 id="搜索镜像"><a href="#搜索镜像" class="headerlink" title="搜索镜像"></a>搜索镜像</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker search mysql</span><br><span class="line">NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED</span><br><span class="line">mysql                             MySQL is a widely used, open-source relation…   11299     [OK]       </span><br></pre></td></tr></table></figure>

<p>过滤搜索<br>docker search mysql –filter=STARS=300 搜索大于300 的mysql</p>
<h5 id="下载镜像"><a href="#下载镜像" class="headerlink" title="下载镜像"></a>下载镜像</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull mysql</span><br></pre></td></tr></table></figure>
<h5 id="删除镜像"><a href="#删除镜像" class="headerlink" title="删除镜像"></a>删除镜像</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker rmi -f [镜像id]                   # 删除指定镜像</span><br><span class="line">docker rmi -f [镜像id] [镜像id] [镜像id]  # 删除多个镜像</span><br><span class="line">docker rmi -f $(docker images -aq)       # 删除全部镜像</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="容器命令"><a href="#容器命令" class="headerlink" title="容器命令"></a>容器命令</h4><ol>
<li>有镜像才能创建容器<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker pull centos #下载centos镜像</span><br></pre></td></tr></table></figure></li>
<li>新建容器启动<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">docker run [可选参数] image</span><br><span class="line"></span><br><span class="line">--name=&quot;xxx&quot;      容器名字</span><br><span class="line">-d                后台方式运行</span><br><span class="line">-it               使用交互方式运行，进入容器查看内容</span><br><span class="line">-p                指定容器的端口 [-p 8080:8080]</span><br><span class="line">	-p ip:主机端口:容器端口</span><br><span class="line">	-p 主机端口:容器端口</span><br><span class="line">	-p 容器端口</span><br><span class="line">	容器端口</span><br><span class="line">	</span><br></pre></td></tr></table></figure>
docker run -d -p 8080:8080 –name tomcat05 tomcat<br>docker run -d -p 8080:8080 –name nginx01 nginx<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">docker run -it centos /bin/bash                 # 启动并进入容器</span><br><span class="line">ls</span><br><span class="line">bin  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var</span><br><span class="line"></span><br><span class="line">exit                                            # 退出容器</span><br></pre></td></tr></table></figure></li>
</ol>
<h5 id="列出所有运行的容器"><a href="#列出所有运行的容器" class="headerlink" title="列出所有运行的容器"></a>列出所有运行的容器</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker ps</span><br><span class="line">CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES</span><br></pre></td></tr></table></figure>

<p>列出所有运行过的容器</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">[root@VM-0-4-centos /]# docker ps -a</span><br><span class="line">CONTAINER ID   IMAGE          COMMAND       CREATED         STATUS                          PORTS     NAMES</span><br><span class="line">ceb21611be50   centos         &quot;/bin/bash&quot;   2 minutes ago   Exited (0) About a minute ago             keen_lumiere</span><br><span class="line">6c0ef68bdcbe   d1165f221234   &quot;/hello&quot;      5 hours ago     Exited (0) 5 hours ago                    dazzling_newton</span><br><span class="line">[root@VM-0-4-centos /]# </span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>列出所有运行过的几个容器 </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@VM-0-4-centos /]# docker ps -a -n=?</span><br><span class="line">CONTAINER ID   IMAGE          COMMAND       CREATED         STATUS                          PORTS     NAMES</span><br><span class="line">ceb21611be50   centos         &quot;/bin/bash&quot;   2 minutes ago   Exited (0) About a minute ago             keen_lumiere</span><br><span class="line">6c0ef68bdcbe   d1165f221234   &quot;/hello&quot;      5 hours ago     Exited (0) 5 hours ago                    dazzling_newton</span><br><span class="line">[root@VM-0-4-centos /]# </span><br></pre></td></tr></table></figure>
<p>列出所有运行过的几个容器的id </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">[root@VM-0-4-centos /]# docker ps -a -n=? -p</span><br><span class="line">CONTAINER ID   IMAGE          COMMAND       CREATED         STATUS                          PORTS     NAMES</span><br><span class="line">ceb21611be50   centos         &quot;/bin/bash&quot;   2 minutes ago   Exited (0) About a minute ago             keen_lumiere</span><br><span class="line">6c0ef68bdcbe   d1165f221234   &quot;/hello&quot;      5 hours ago     Exited (0) 5 hours ago                    dazzling_newton</span><br><span class="line">[root@VM-0-4-centos /]# </span><br></pre></td></tr></table></figure>

<h5 id="进入容器"><a href="#进入容器" class="headerlink" title="进入容器"></a>进入容器</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it c8530dbbe3b4 /bin/bash </span><br><span class="line">exec 是在容器中打开新的终端，并且可以启动新的进程 </span><br><span class="line">attach 直接进入容器启动命令的终端，不会启动新的进程</span><br></pre></td></tr></table></figure>
<h5 id="退出容器"><a href="#退出容器" class="headerlink" title="退出容器"></a>退出容器</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">exit              #停止容器并退出</span><br><span class="line">Ctrl + P + Q      #不停止容器，退出</span><br></pre></td></tr></table></figure>
<h5 id="删除容器"><a href="#删除容器" class="headerlink" title="删除容器"></a>删除容器</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">docker rm 容器id                          #删除指定容器，不能删除正在运行的容器，强制删除用 rm -f</span><br><span class="line">docker rm -f $(docker images -aq)         #删除所有容器</span><br><span class="line">docker ps -a -q|xargs docker rm            #删除所有容器</span><br></pre></td></tr></table></figure>
<h5 id="启动停止容器"><a href="#启动停止容器" class="headerlink" title="启动停止容器"></a>启动停止容器</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker start [容器id or 容器名]           # 启动容器</span><br><span class="line">docker restart [容器id or 容器名]         # 重启容器</span><br><span class="line">docker stop [容器id or 容器名]            # 停止容器</span><br><span class="line">docker kill [容器id or 容器名]            # 强制停止容器</span><br></pre></td></tr></table></figure>
<h5 id="保存容器"><a href="#保存容器" class="headerlink" title="保存容器"></a>保存容器</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">docker commit -a &quot;vankana&lt;2395073039.com&gt;&quot; -m &quot;info&quot; 4ece798ad929 v-mysql:v1</span><br><span class="line">sha256:24026883cb0346698df1138c7b42b847a8063a31ac9a192654b04023b0cfedd4</span><br><span class="line">-a :提交的镜像作者；</span><br><span class="line">-c :使用Dockerfile指令来创建镜像；</span><br><span class="line">-m :提交时的说明文字；</span><br><span class="line">-p :在commit时，将容器暂停。</span><br></pre></td></tr></table></figure>

<h5 id="宿主机复制到容器"><a href="#宿主机复制到容器" class="headerlink" title="宿主机复制到容器"></a>宿主机复制到容器</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker cp /opt/test.js testtomcat:/usr/local/tomcat/webapps/test/js</span><br></pre></td></tr></table></figure>

<h5 id="容器复制到宿主机"><a href="#容器复制到宿主机" class="headerlink" title="容器复制到宿主机"></a>容器复制到宿主机</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker cp testtomcat:/usr/local/tomcat/webapps/test/js/test.js /opt</span><br></pre></td></tr></table></figure>

<h5 id="扩展"><a href="#扩展" class="headerlink" title="扩展"></a>扩展</h5><h6 id="启动后台运行"><a href="#启动后台运行" class="headerlink" title="启动后台运行"></a>启动后台运行</h6><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">命令 </span><br><span class="line">docker run -d 容器名 </span><br><span class="line">例子 </span><br><span class="line">docker run -d centos </span><br><span class="line"># 启动centos，使用后台方式启动 </span><br><span class="line"># 问题： 使用docker ps 查看，发现容器已经退出了！ </span><br><span class="line"># 解释：Docker容器后台运行，就必须有一个前台进程，容器运行的命令如果不是那些一直挂起的命 令，就会自动退出。 </span><br><span class="line"># 比如，你运行了nginx服务，但是docker前台没有运行应用，这种情况下，容器启动后，会立即自 杀，因为他觉得没有程序了，所以最好的情况是，将你的应用使用前台进程的方式运行启动。</span><br></pre></td></tr></table></figure>

<p> docker run -p 8848:8848 -v /home/nacos:/home –name mynaocs01 -d d23bdf5b1b1b</p>
<h6 id="启动mysqk-5-7"><a href="#启动mysqk-5-7" class="headerlink" title="启动mysqk:5.7"></a>启动mysqk:5.7</h6><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -p 3306:3306 --name mysql01 -v /home/docker/data/mysql/conf:/etc/mysql/conf.d -v /home/docker/data/mysql/logs:/logs -v /home/docker/data/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:5.7</span><br></pre></td></tr></table></figure>

<h6 id="启动-nginx"><a href="#启动-nginx" class="headerlink" title="启动 nginx"></a>启动 nginx</h6><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run --name nginx81 -d -p 81:80 -v /root/work/html:/usr/share/nginx/html -v /home/docker/data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/docker/data/nginx/log:/var/log/nginx -v /home/docker/data/nginx/conf.d:/etc/nginx/conf.d -d nginx  </span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">docker run --name nginx81 -d -p 81:80 </span><br><span class="line">-v /root/work/html:/usr/share/nginx/html</span><br><span class="line">-v /home/docker/data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf</span><br><span class="line">-v /home/docker/data/nginx/log:/var/log/nginx</span><br><span class="line">-v /home/docker/data/nginx/conf.d:/etc/nginx/conf.d -d nginx </span><br></pre></td></tr></table></figure>

<p>坑</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">server &#123;</span><br><span class="line">        listen       80;</span><br><span class="line">        server_name  localhost;</span><br><span class="line">        #charset koi8-r;</span><br><span class="line">        #access_log  logs/host.access.log  main;</span><br><span class="line">        #error_page  404              /404.html;</span><br><span class="line">        # redirect server error pages to the static page /50x.html</span><br><span class="line">        #</span><br><span class="line">        error_page   500 502 503 504  /50x.html;</span><br><span class="line">        location = /50x.html &#123;</span><br><span class="line">            root   html;</span><br><span class="line">        &#125;</span><br><span class="line">        location /user/ &#123;  </span><br><span class="line">            client_max_body_size  300m;   </span><br><span class="line">            proxy_connect_timeout 300s;   </span><br><span class="line">            proxy_send_timeout 300s;  </span><br><span class="line">            proxy_read_timeout 300s;   </span><br><span class="line">            proxy_pass   http://47.121.23.142:18081;   </span><br><span class="line">         &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h6 id="启动-Java"><a href="#启动-Java" class="headerlink" title="启动 Java"></a>启动 Java</h6><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker run --name nginx81 -d -p 81:80 -v /root/work/html:/usr/share/nginx/html -v </span><br><span class="line">-e ES_JAVA_OPTS=&quot;-Xms64m -Xmx512m&quot;</span><br></pre></td></tr></table></figure>



<h3 id="Docker-镜像"><a href="#Docker-镜像" class="headerlink" title="Docker 镜像"></a>Docker 镜像</h3><h3 id="容器数据卷"><a href="#容器数据卷" class="headerlink" title="容器数据卷"></a>容器数据卷</h3><p>使用命令挂载卷</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -it -v /home/ceshi:/home centos /bin/bash</span><br></pre></td></tr></table></figure>
<p>查看数据卷是否挂载</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">docker inspect 661be6f56d4d</span><br><span class="line"></span><br><span class="line">        &quot;Mounts&quot;: [</span><br><span class="line">            &#123;</span><br><span class="line">                &quot;Type&quot;: &quot;bind&quot;,</span><br><span class="line">                &quot;Source&quot;: &quot;/home/ceshi&quot;, # 主机地址</span><br><span class="line">                &quot;Destination&quot;: &quot;/home&quot;,  # 容器地址</span><br><span class="line">                &quot;Mode&quot;: &quot;&quot;,</span><br><span class="line">                &quot;RW&quot;: true,</span><br><span class="line">                &quot;Propagation&quot;: &quot;rprivate&quot;</span><br><span class="line">            &#125;</span><br><span class="line">        ],</span><br></pre></td></tr></table></figure>

<h3 id="数据卷容器"><a href="#数据卷容器" class="headerlink" title="数据卷容器"></a>数据卷容器</h3><blockquote>
<p>多个容器之间实现数据共享</p>
</blockquote>
<ol>
<li><p>启动容器</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -it --name docker01 vankan/debian:0.2 /bin/bash</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker run -it --name docker02 --volumes-from docker01 vankan/debian:0.2 /bin/bash</span><br><span class="line"># 同步docker01 数据卷</span><br></pre></td></tr></table></figure>

<p>–volumes-from 挂载docker01数据卷，类似继承，但又不是</p>
</li>
<li><p>查看数据是否共享</p>
</li>
</ol>
<p><strong>容器之间配置信息的传递，数据卷的生命周期一直持续到没有容器使用它为止。</strong></p>
<p><strong>存储在本机的文件则会一直保留！</strong></p>
<h3 id="DockerFile-构建镜像"><a href="#DockerFile-构建镜像" class="headerlink" title="DockerFile 构建镜像"></a>DockerFile 构建镜像</h3><blockquote>
<p>dockerFile 是用来构建镜像的文件，命令参数脚本</p>
</blockquote>
<h4 id="基础"><a href="#基础" class="headerlink" title="基础"></a>基础</h4><ol>
<li><p>每条保留字指令都必须为大写字母且后面要跟随至少一个参数</p>
</li>
<li><p>指令按照从上到下，顺序执行</p>
</li>
<li><p>“#”表示注释</p>
</li>
<li><p>每条指令都会创建一个新的镜像层，并对镜像进行提交</p>
</li>
</ol>
<h4 id="关键字"><a href="#关键字" class="headerlink" title="关键字"></a>关键字</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">FROM           # 基础镜像，当前新镜像是基于哪个镜像的 </span><br><span class="line">MAINTAINER     # 镜像维护者的姓名混合邮箱地址 </span><br><span class="line">RUN            # 容器构建时需要运行的命令 </span><br><span class="line">EXPOSE         # 当前容器对外保留出的端口 </span><br><span class="line">WORKDIR        # 指定在创建容器后，终端默认登录的进来工作目录，一个落脚点 </span><br><span class="line">ENV            # 用来在构建镜像过程中设置环境变量 </span><br><span class="line">ADD            # 将宿主机目录下的文件拷贝进镜像且ADD命令会自动处理URL和解压tar压缩包 </span><br><span class="line">COPY           # 类似ADD，拷贝文件和目录到镜像中！ </span><br><span class="line">VOLUME         # 容器数据卷，用于数据保存和持久化工作 </span><br><span class="line">CMD            # 指定一个容器启动时要运行的命令，dockerFile中可以有多个CMD指令，但只有最 后一个生效！ </span><br><span class="line">ENTRYPOINT     # 指定一个容器启动时要运行的命令！和CMD一样 </span><br><span class="line">ONBUILD        # 当构建一个被继承的DockerFile时运行命令，父镜像在被子镜像继承后，父镜像的 ONBUILD被触发</span><br></pre></td></tr></table></figure>



<h4 id="初步构建"><a href="#初步构建" class="headerlink" title="初步构建"></a>初步构建</h4><ol>
<li> 创建目录</li>
</ol>
   <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir docker-text</span><br></pre></td></tr></table></figure>

<ol start="2">
<li><p>创建DockerFile文件</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim dockerfile-centos</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">FROM centos</span><br><span class="line"></span><br><span class="line">VOLUME [&quot;/volume01&quot;,&quot;/volume02&quot;] #最新版本(20)docker 旧版 [&quot;volume01&quot;,&quot;volume02&quot;]</span><br><span class="line"></span><br><span class="line">CMD echo &quot;----end-----&quot;</span><br><span class="line">CMD /bin/bash</span><br></pre></td></tr></table></figure>

<p>不考虑版本的话会报错</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker: Error response from daemon: OCI runtime create failed: invalid mount &#123;Destination:volume01 Type:bind Source:/.../_data Options:[rbind]&#125;: mount destination volume01 not absolute: unknown.</span><br><span class="line">ERRO[0000] error waiting for container: context canceled</span><br></pre></td></tr></table></figure></li>
<li><p>启动</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">docker build -f /home/docker-text/dockerfile-centos -t vankan/centos:0.1 .</span><br><span class="line"># /home/docker-text/dockerfile-centos 当前文件地址</span><br><span class="line"># vankan/centos:0.1 文件版本:版本号</span><br><span class="line"># .  当前地址</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">Sending build context to Docker daemon  2.048kB</span><br><span class="line">Step 1/4 : FROM centos</span><br><span class="line"> ---&gt; a0477e85b8ae</span><br><span class="line">Step 2/4 : VOLUME [&quot;volume01&quot;,&quot;volume02&quot;]</span><br><span class="line"> ---&gt; Running in 64f5a15dafec</span><br><span class="line">Removing intermediate container 64f5a15dafec</span><br><span class="line"> ---&gt; 970bde4042e2</span><br><span class="line">Step 3/4 : CMD echo &quot;----end-----&quot;</span><br><span class="line"> ---&gt; Running in f0607dc69cd2</span><br><span class="line">Removing intermediate container f0607dc69cd2</span><br><span class="line"> ---&gt; b35d79689498</span><br><span class="line">Step 4/4 : CMD /bin/bash</span><br><span class="line"> ---&gt; Running in c90bf80a187a</span><br><span class="line">Removing intermediate container c90bf80a187a</span><br><span class="line"> ---&gt; 99e747059616</span><br><span class="line">Successfully built 99e747059616</span><br><span class="line">Successfully tagged vankan/centos:0.1</span><br></pre></td></tr></table></figure></li>
<li><p>查看是否生成镜像</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker images</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">REPOSITORY           TAG       IMAGE ID       CREATED              SIZE</span><br><span class="line">vankan/centos        0.1       99e747059616   About a minute ago   249MB</span><br></pre></td></tr></table></figure></li>
<li><p>启动生成的镜像</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -it 99e747059616 /bin/bash        </span><br></pre></td></tr></table></figure></li>
</ol>
<h4 id="实战"><a href="#实战" class="headerlink" title="实战"></a>实战</h4><ol>
<li> 创建目录</li>
</ol>
   <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mkdir dockerfile</span><br></pre></td></tr></table></figure>

<ol start="2">
<li><p>创建DockerFile文件</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">vim mydockerfille</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">FROM centos</span><br><span class="line">MAINTAINER vanka&lt;2395073039@qq.com&gt;</span><br><span class="line"></span><br><span class="line">ENV MYPATH /usr/local                # 启动后直接到工作目录</span><br><span class="line">WORKDIR $MYPATH</span><br><span class="line"></span><br><span class="line">RUN yum -y install vim               # 安装vim</span><br><span class="line">RUM yum -y install net-tools         # net-tools</span><br><span class="line"></span><br><span class="line">EXPOSE 80</span><br><span class="line"></span><br><span class="line">CMD echo $MYPATH</span><br><span class="line">CMD echo &quot;-----end-----&quot;</span><br><span class="line">CMD /bin/bash</span><br></pre></td></tr></table></figure></li>
<li><p>通过文件构建镜像</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker build -f mydockerfile -t vank/centos:1.0 .</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Sending build context to Docker daemon  2.048kB</span><br><span class="line">...</span><br><span class="line">Successfully built 400a18c52f3e</span><br><span class="line">Successfully tagged vank/centos:1.0</span><br></pre></td></tr></table></figure></li>
<li><p>启动构建的镜像</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"># docker images</span><br><span class="line"></span><br><span class="line">REPOSITORY           TAG       IMAGE ID       CREATED        SIZE</span><br><span class="line">vank/centos          1.0       400a18c52f3e   2 hours ago    339MB</span><br><span class="line"></span><br><span class="line"># docker run -it 400a18c52f3e</span><br><span class="line"></span><br><span class="line">[root@0077a110db80 local]# pwd</span><br><span class="line">/usr/local</span><br><span class="line"># 测试 vim config</span><br></pre></td></tr></table></figure></li>
<li><p>查看镜像制作过程</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker history 400a18c52f3e</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">root@raspbian:~# docker history 400a18c52f3e</span><br><span class="line">IMAGE          CREATED        CREATED BY                                      SIZE      COMMENT</span><br><span class="line">400a18c52f3e   2 hours ago    /bin/sh -c #(nop)  CMD [&quot;/bin/sh&quot; &quot;-c&quot; &quot;/bin…   0B        </span><br><span class="line">e8db89758f2c   2 hours ago    /bin/sh -c #(nop)  CMD [&quot;/bin/sh&quot; &quot;-c&quot; &quot;echo…   0B        </span><br><span class="line">0d69d0707672   2 hours ago    /bin/sh -c #(nop)  CMD [&quot;/bin/sh&quot; &quot;-c&quot; &quot;echo…   0B        </span><br><span class="line">d5c6bee575e4   2 hours ago    /bin/sh -c #(nop)  EXPOSE 80                    0B        </span><br><span class="line">f7f55dd5662e   2 hours ago    /bin/sh -c yum -y install net-tools             27.1MB    </span><br><span class="line">95b4d4bc2f90   2 hours ago    /bin/sh -c yum -y install vim                   62.9MB    </span><br><span class="line">8d3b7985c39a   2 hours ago    /bin/sh -c #(nop) WORKDIR /usr/local            0B        </span><br><span class="line">42e912b21dd3   2 hours ago    /bin/sh -c #(nop)  ENV MYPATH=/usr/local        0B        </span><br><span class="line">0b49db12e1d3   2 hours ago    /bin/sh -c #(nop)  MAINTAINER vanka&lt;23950730…   0B        </span><br><span class="line">a0477e85b8ae   8 months ago   /bin/sh -c #(nop)  CMD [&quot;/bin/bash&quot;]            0B        </span><br><span class="line">&lt;missing&gt;      8 months ago   /bin/sh -c #(nop)  LABEL org.label-schema.sc…   0B        </span><br><span class="line">&lt;missing&gt;      8 months ago   /bin/sh -c #(nop) ADD file:edd6e1253ec7bbb67…   249MB     </span><br><span class="line"></span><br><span class="line">root@raspbian:~# docker history 4e692710b876</span><br><span class="line">IMAGE          CREATED      CREATED BY                                      SIZE      COMMENT</span><br><span class="line">4e692710b876   6 days ago   /bin/sh -c #(nop)  CMD [&quot;nginx&quot; &quot;-g&quot; &quot;daemon…   0B        </span><br><span class="line">&lt;missing&gt;      6 days ago   /bin/sh -c #(nop)  STOPSIGNAL SIGQUIT           0B        </span><br><span class="line">&lt;missing&gt;      6 days ago   /bin/sh -c #(nop)  EXPOSE 80                    0B        </span><br><span class="line">&lt;missing&gt;      6 days ago   /bin/sh -c #(nop)  ENTRYPOINT [&quot;/docker-entr…   0B        </span><br><span class="line">&lt;missing&gt;      6 days ago   /bin/sh -c #(nop) COPY file:09a214a3e07c919a…   4.61kB    </span><br><span class="line">&lt;missing&gt;      6 days ago   /bin/sh -c #(nop) COPY file:0fd5fca330dcd6a7…   1.04kB    </span><br><span class="line">&lt;missing&gt;      6 days ago   /bin/sh -c #(nop) COPY file:0b866ff3fc1ef5b0…   1.96kB    </span><br><span class="line">&lt;missing&gt;      6 days ago   /bin/sh -c #(nop) COPY file:65504f71f5855ca0…   1.2kB     </span><br><span class="line">&lt;missing&gt;      6 days ago   /bin/sh -c set -x     &amp;&amp; addgroup --system -…   62.4MB    </span><br><span class="line">&lt;missing&gt;      6 days ago   /bin/sh -c #(nop)  ENV PKG_RELEASE=1~buster     0B        </span><br><span class="line">&lt;missing&gt;      6 days ago   /bin/sh -c #(nop)  ENV NJS_VERSION=0.6.1        0B        </span><br><span class="line">&lt;missing&gt;      6 days ago   /bin/sh -c #(nop)  ENV NGINX_VERSION=1.21.1     0B        </span><br><span class="line">&lt;missing&gt;      6 days ago   /bin/sh -c #(nop)  LABEL maintainer=NGINX Do…   0B        </span><br><span class="line">&lt;missing&gt;      7 days ago   /bin/sh -c #(nop)  CMD [&quot;bash&quot;]                 0B        </span><br><span class="line">&lt;missing&gt;      7 days ago   /bin/sh -c #(nop) ADD file:a62249c8d6f38120b…   63.5MB </span><br></pre></td></tr></table></figure></li>
</ol>
<h4 id="实例"><a href="#实例" class="headerlink" title="实例"></a>实例</h4><ol>
<li><p>准备<a target="_blank" rel="noopener" href="http://archive.apache.org/dist/tomcat/tomcat-9/v9.0.33/bin/apache-tomcat-9.0.33.tar.gz">tomcat</a> 、<a target="_blank" rel="noopener" href="https://www.oracle.com/cn/java/technologies/javase/javase-jdk8-downloads.html">jdk 1.8</a>  和 jar包</p>
</li>
<li><p>创建dockerFile文件</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">FROM  centos</span><br><span class="line">MAINTAINER vanka&lt;2395073039@qq.com&gt;</span><br><span class="line"></span><br><span class="line">COPY docker-spring-jar-0.0.1-SNAPSHOT.jar /user/local/work/docker-spring-jar-0.0.1-SNAPSHOT.jar</span><br><span class="line"></span><br><span class="line">ADD jdk-8u301-linux-aarch64.tar.gz /usr/local/</span><br><span class="line">ADD apache-tomcat-9.0.33.tar.gz /usr/local/</span><br><span class="line">#安装vim编辑器 </span><br><span class="line">RUN yum -y install vim </span><br><span class="line">#设置工作访问时候的WORKDIR路径，登录落脚点 </span><br><span class="line">ENV MYPATH /usr/local </span><br><span class="line">WORKDIR $MYPATH </span><br><span class="line">#配置java与tomcat环境变量</span><br><span class="line">ENV JAVA_HOME /usr/local/jdk1.8.0_301</span><br><span class="line">ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar </span><br><span class="line">ENV CATALINA_HOME /usr/local/apache-tomcat-9.0.33 </span><br><span class="line">ENV CATALINA_BASE /usr/local/apache-tomcat-9.0.33 </span><br><span class="line">ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin</span><br><span class="line"></span><br><span class="line">CMD [&quot;-jar /user/local/work/docker-spring-jar-0.0.1-SNAPSHOT.jar&quot;]</span><br><span class="line"></span><br><span class="line">#容器运行时监听的端口 </span><br><span class="line">EXPOSE 8080</span><br><span class="line">CMD /usr/local/apache-tomcat-9.0.33/bin/startup.sh &amp;&amp; tail -F /usr/local/apache-tomcat-9.0.33/bin/logs/catalina.out</span><br></pre></td></tr></table></figure></li>
<li><p>生成镜像，并运行</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker run -d -p 9090:8080 --name mytomcat -v /home/tomcat/test:/usr/local/apache-tomcat- 9.0.33/webapps/test -v /home/kuangshen/build/tomcat/tomcat9logs/:/usr/local/apache-tomcat-9.0.33/logs --privileged=true diytomcat</span><br></pre></td></tr></table></figure></li>
</ol>
<h4 id="dockerHub-发布镜像"><a href="#dockerHub-发布镜像" class="headerlink" title="dockerHub 发布镜像"></a>dockerHub 发布镜像</h4><ol>
<li>登录</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"># docker login -u vankana</span><br><span class="line">Password: </span><br><span class="line">WARNING! Your password will be stored unencrypted in /root/.docker/config.json.</span><br><span class="line">Configure a credential helper to remove this warning. See</span><br><span class="line">https://docs.docker.com/engine/reference/commandline/login/#credentials-store</span><br><span class="line"></span><br><span class="line">Login Succeeded</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>发布</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker push vankana/xxx:x.x</span><br></pre></td></tr></table></figure>

<p>ps: 如果需要版本信息</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker tag [容器id] vankana/xxx:x.x</span><br></pre></td></tr></table></figure>



<h4 id="阿里云-发布镜像"><a href="#阿里云-发布镜像" class="headerlink" title="阿里云 发布镜像"></a>阿里云 发布镜像</h4><ol>
<li><p>删除登录凭证</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker logout</span><br><span class="line">Removing login credentials for https://index.docker.io/v1/</span><br></pre></td></tr></table></figure></li>
<li><p>登录阿里云</p>
</li>
<li><p>创建 命名空间</p>
</li>
<li><p>创建 仓库</p>
</li>
</ol>
<p><img src="C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20210825093637965.png" alt="image-20210825093637965"></p>
<ol start="4">
<li><p>登录</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">docker login --username=可怜的于小凡 registry.cn-hangzhou.aliyuncs.com</span><br><span class="line">Password: </span><br><span class="line"></span><br><span class="line">WARNING! Your password will be stored unencrypted in /root/.docker/config.json.</span><br><span class="line">Configure a credential helper to remove this warning. See</span><br><span class="line">https://docs.docker.com/engine/reference/commandline/login/#credentials-store</span><br><span class="line"></span><br><span class="line">Login Succeeded</span><br></pre></td></tr></table></figure></li>
<li><p>上传</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">docker tag e6370e15aee0 registry.cn-hangzhou.aliyuncs.com/ali-vanka/one-precious:v1.0 # 设置 tag</span><br><span class="line">docker push registry.cn-hangzhou.aliyuncs.com/ali-vanka/one-precious:v1.0             # 上传</span><br></pre></td></tr></table></figure></li>
</ol>
<h4 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h4><ul>
<li><a target="_blank" rel="noopener" href="https://nacos.io/zh-cn/docs/quick-start-docker.html">nacos 镜像制作</a></li>
</ul>
<h3 id="Docker网络原理"><a href="#Docker网络原理" class="headerlink" title="Docker网络原理"></a>Docker网络原理</h3><h4 id="ip查看"><a href="#ip查看" class="headerlink" title="ip查看"></a>ip查看</h4><ol>
<li>查看本地ip</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"> ip addr</span><br><span class="line">1: lo: ...</span><br><span class="line">2: eth0:  ...</span><br><span class="line">3: wlan0:  ...</span><br><span class="line">4: docker_gwbridge: ...</span><br><span class="line">5: docker0: ...</span><br><span class="line">85: veth0412ef9@if84: ...</span><br></pre></td></tr></table></figure>

<ol start="2">
<li>查看容器内ip</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it 82b8e0bfdf31 /bin/bash</span><br><span class="line">[root@82b8e0bfdf31 local]# ip addr</span><br><span class="line">1: lo: ...127.0.0.1/8  ...</span><br><span class="line">84: eth0@if85: ...172.17.0.5/16 ...</span><br><span class="line"></span><br></pre></td></tr></table></figure>

<ol start="3">
<li>服务器ping 容器内的网络</li>
</ol>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">ping 172.17.0.5</span><br><span class="line">PING 172.17.0.5 (172.17.0.5) 56(84) bytes of data.</span><br><span class="line">64 bytes from 172.17.0.5: icmp_seq=1 ttl=64 time=0.298 ms</span><br><span class="line">64 bytes from 172.17.0.5: icmp_seq=2 ttl=64 time=0.182 ms</span><br></pre></td></tr></table></figure>

<blockquote>
<p>原理</p>
</blockquote>
<ol>
<li><p>每一个安装了Docker的linux主机都有一个docker0的虚拟网卡。这是个桥接网卡，使用了veth-pair技术！</p>
</li>
<li><p>每启动一个容器，linux主机就会多了一个虚拟网卡</p>
</li>
</ol>
<p><strong>–link</strong></p>
<blockquote>
<p>直接把需要link的主机的域名和ip直接配置到了hosts文件中了</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">docker exec -it tomcat03 cat /etc/hosts </span><br><span class="line">127.0.0.1 localhost </span><br><span class="line">::1 localhost ip6-localhost ip6-loopback </span><br><span class="line">fe00::0 ip6-localnet </span><br><span class="line">ff00::0 ip6-mcastprefix </span><br><span class="line">ff02::1 ip6-allnodes </span><br><span class="line">ff02::2 ip6-allrouters </span><br><span class="line">172.18.0.3 tomcat02 b80da266a3ad # 发现tomcat2直接被写在这里 </span><br><span class="line">172.18.0.4 a3a4a17a2b70</span><br></pre></td></tr></table></figure>



<h4 id="自定义网络"><a href="#自定义网络" class="headerlink" title="自定义网络"></a>自定义网络</h4><ol>
<li><p>查看所有网络类型</p>
 <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">docker network ls</span><br><span class="line">NETWORK ID     NAME              DRIVER    SCOPE</span><br><span class="line">14b501a80fd2   bridge            bridge    local</span><br><span class="line">a4d727d0c8c9   docker_gwbridge   bridge    local</span><br><span class="line">5c2c4cbdf867   host              host      local</span><br><span class="line">4a8daaf8650d   none              null      local</span><br></pre></td></tr></table></figure></li>
<li><p>网络模式</p>
<table>
<thead>
<tr>
<th><strong>网络模式</strong></th>
<th><strong>配置</strong></th>
<th><strong>说明</strong></th>
</tr>
</thead>
<tbody><tr>
<td>bridge模式</td>
<td>–net=bridge</td>
<td>默认值，在Docker网桥docker0上为容器创建新的网络栈</td>
</tr>
<tr>
<td>none模式</td>
<td>–net=none</td>
<td>不配置网络，用户可以稍后进入容器，自行配置</td>
</tr>
<tr>
<td>container</td>
<td>--net=container:name/id</td>
<td>容器和另外一个容器共享Network namespace。</td>
</tr>
<tr>
<td>host模式</td>
<td>–net=host</td>
<td>容器和宿主机共享Network namespace</td>
</tr>
<tr>
<td>用户自定义</td>
<td>–net=自定义网络</td>
<td>用户自己使用network相关命令定义网络，创建容器的</td>
</tr>
</tbody></table>
</li>
</ol>
<h5 id="自定义创建一个网络"><a href="#自定义创建一个网络" class="headerlink" title="自定义创建一个网络"></a>自定义创建一个网络</h5><ol>
<li><p>命令生成</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 mynet</span><br></pre></td></tr></table></figure>

<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">自定义创建的默认default &quot;bridge&quot;</span><br><span class="line">--subnet 192.168.0.0/16      范围 192.168.255.255</span><br><span class="line">--gateway 192.168.0.1        网关</span><br></pre></td></tr></table></figure>

<blockquote>
<p>坑 修改后外网无法访问 改DNS</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">vi /etc/resolv.conf</span><br><span class="line">nameserver 114.114.114.114   # 国内服务器</span><br><span class="line"></span><br><span class="line">systemctl restart network    # 重启network服务</span><br></pre></td></tr></table></figure></li>
</ol>
<h3 id="IDEA整合Docker"><a href="#IDEA整合Docker" class="headerlink" title="IDEA整合Docker"></a>IDEA整合Docker</h3><h3 id="DockerCompose-集群"><a href="#DockerCompose-集群" class="headerlink" title="DockerCompose 集群"></a>DockerCompose 集群</h3><h3 id="DockerSwarm-集群管理"><a href="#DockerSwarm-集群管理" class="headerlink" title="DockerSwarm 集群管理"></a>DockerSwarm 集群管理</h3><h3 id="CI-CD-Jenkins"><a href="#CI-CD-Jenkins" class="headerlink" title="CI\CD Jenkins"></a>CI\CD Jenkins</h3><h3 id="问题"><a href="#问题" class="headerlink" title="问题"></a>问题</h3><h5 id="centos7-docker端口映射到宿主机后外网无法访问"><a href="#centos7-docker端口映射到宿主机后外网无法访问" class="headerlink" title="centos7 docker端口映射到宿主机后外网无法访问"></a>centos7 docker端口映射到宿主机后外网无法访问</h5><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">//  vi /etc/sysctl.conf</span><br><span class="line">添加代码：</span><br><span class="line">net.ipv4.ip_forward=1</span><br><span class="line"> </span><br><span class="line">重启network服务</span><br><span class="line">//  systemctl restart network</span><br><span class="line"> </span><br><span class="line">查看是否修改成功</span><br><span class="line">// sysctl net.ipv4.ip_forward</span><br><span class="line"> </span><br><span class="line">如果返回为“net.ipv4.ip_forward = 1”则表示成功了</span><br></pre></td></tr></table></figure>
<p><a target="_blank" rel="noopener" href="https://blog.csdn.net/yuchenai/article/details/113246904"></a></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">[root@VM-0-4-centos ~]# ip a</span><br><span class="line">1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000</span><br><span class="line">    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00</span><br><span class="line">    inet 127.0.0.1/8 scope host lo</span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">    inet6 ::1/128 scope host </span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc pfifo_fast state UP group default qlen 1000</span><br><span class="line">    link/ether 52:54:00:ce:fe:9c brd ff:ff:ff:ff:ff:ff</span><br><span class="line">    inet 172.17.0.4/20 brd 172.17.15.255 scope global eth0</span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">    inet6 fe80::5054:ff:fece:fe9c/64 scope link </span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">3: docker0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UP group default </span><br><span class="line">    link/ether 02:42:cf:69:50:d7 brd ff:ff:ff:ff:ff:ff</span><br><span class="line">    inet 172.18.0.1/16 brd 172.18.255.255 scope global docker0</span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">    inet6 fe80::42:cfff:fe69:50d7/64 scope link </span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">19: veth843fa5d@if18: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue master docker0 state UP group default </span><br><span class="line">    link/ether 12:92:55:df:c1:66 brd ff:ff:ff:ff:ff:ff link-netnsid 0</span><br><span class="line">    inet6 fe80::1092:55ff:fedf:c166/64 scope link </span><br><span class="line">       valid_lft forever preferred_lft forever</span><br></pre></td></tr></table></figure>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">[root@VM-0-4-centos ~]# ip a</span><br><span class="line">1: lo: &lt;LOOPBACK,UP,LOWER_UP&gt; mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000</span><br><span class="line">    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00</span><br><span class="line">    inet 127.0.0.1/8 scope host lo</span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">    inet6 ::1/128 scope host </span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">2: eth0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc mq state UP group default qlen 1000</span><br><span class="line">    link/ether e4:5f:01:1b:85:a9 brd ff:ff:ff:ff:ff:ff</span><br><span class="line">    inet 192.168.0.19/24 brd 192.168.0.255 scope global dynamic noprefixroute eth0</span><br><span class="line">       valid_lft 65142sec preferred_lft 54342sec</span><br><span class="line">    inet6 fe80::e2ab:3203:d445:5284/64 scope link </span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">3: wlan0: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc fq state DOWN group default qlen 1000</span><br><span class="line">    link/ether e4:5f:01:1b:85:aa brd ff:ff:ff:ff:ff:ff</span><br><span class="line">4: docker_gwbridge: &lt;NO-CARRIER,BROADCAST,MULTICAST,UP&gt; mtu 1500 qdisc noqueue state DOWN group default </span><br><span class="line">    link/ether 02:42:b6:17:27:77 brd ff:ff:ff:ff:ff:ff</span><br><span class="line">    inet 172.18.0.1/16 brd 172.18.255.255 scope global docker_gwbridge</span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">5: docker0: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue state UP group default </span><br><span class="line">    link/ether 02:42:9b:37:66:de brd ff:ff:ff:ff:ff:ff</span><br><span class="line">    inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0</span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">    inet6 fe80::42:9bff:fe37:66de/64 scope link </span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">7: veth12e4707@if6: &lt;BROADCAST,MULTICAST,UP,LOWER_UP&gt; mtu 1500 qdisc noqueue master docker0 state UP group default </span><br><span class="line">    link/ether 0a:b8:74:50:c4:8e brd ff:ff:ff:ff:ff:ff link-netnsid 0</span><br><span class="line">    inet 169.254.126.155/16 brd 169.254.255.255 scope global noprefixroute veth12e4707</span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line">    inet6 fe80::9e6f:4a30:e8b0:550/64 scope link </span><br><span class="line">       valid_lft forever preferred_lft forever</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>无效</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">iptables -t nat -A POSTROUTING -s 172.18.0.1/16 ! -o docker0 -j MASQUERADE</span><br></pre></td></tr></table></figure>

<h5 id="dockerFile生成镜像后，运行失败"><a href="#dockerFile生成镜像后，运行失败" class="headerlink" title="dockerFile生成镜像后，运行失败"></a>dockerFile生成镜像后，运行失败</h5><blockquote>
<p>docker: Error response from daemon:<br>OCI runtime create failed: invalid mount {Destination:volume01 Type:bind Source:/var/lib/docker/volumes/cbab1d21c080c9a60ff3c940605ed919da5213e0b34f9f8cabaecf1455dad201/_data Options:[rbind]}: mount destination volume01 not absolute: unknown.<br>ERRO[0000] error waiting for container: context canceled </p>
</blockquote>
<div id="paginator"></div></div><div id="post-footer"><hr><a href="/vcb/2021/09/12/DeBian/">← Prev DeBian</a><span style="color: #fe2"> | </span><a href="/vcb/2021/08/23/RaspberryPi/">RaspberryPi Next →</a><hr></div><div id="bottom-btn"><a id="to-index" href="#post-index" title="index">≡</a><a id="to-top" href="#post-title" title="to top">∧</a></div><div id="Valine"></div><script>new Valine({
 el: '#Valine'
 , appId: ''
 , appKey: ''
 , placeholder: '此条评论委托企鹅物流发送'
})</script></div></article><aside><div id="about"><a href="/vcb/" id="logo"><img src="https://ak.hypergryph.com/assets/index/images/ak/pc/faction/1.png" alt="Logo"></a><h1 id="Dr"><a href="/"> Dr.VanKa</a></h1><section id="total"><a id="total-archives" href="/vcb/archives"><span class="total-title">Archives Total:</span><span class="total-number">12</span></a><div id="total-tags"><span class="total-title">Tags:</span><span class="total-number">13</span></div><div id="total-categories"><span class="total-title">Categories:</span><span class="total-number">1</span></div></section></div><div id="aside-block"><h1>INDEX</h1><div id="post-index"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Docker%E6%A6%82%E8%BF%B0"><span class="toc-number">1.</span> <span class="toc-text">Docker概述</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Docker%E5%AE%89%E8%A3%85"><span class="toc-number">1.0.1.</span> <span class="toc-text">Docker安装</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#Debian%E7%89%88%E6%9C%AC"><span class="toc-number">1.0.1.1.</span> <span class="toc-text">Debian版本</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Windows%E7%89%88%E6%9C%AC"><span class="toc-number">1.0.1.2.</span> <span class="toc-text">Windows版本</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E7%8E%AF%E5%A2%83%E5%87%86%E5%A4%87"><span class="toc-number">1.0.1.2.1.</span> <span class="toc-text">环境准备</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#Linux%E7%89%88%E6%9C%AC"><span class="toc-number">1.0.1.3.</span> <span class="toc-text">Linux版本</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E7%8E%AF%E5%A2%83%E6%9F%A5%E7%9C%8B"><span class="toc-number">1.0.1.3.1.</span> <span class="toc-text">环境查看</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%8D%B8%E8%BD%BD%E6%97%A7%E7%89%88%E6%9C%AC"><span class="toc-number">1.0.1.3.2.</span> <span class="toc-text">卸载旧版本</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%B8%8B%E8%BD%BD%E5%AE%89%E8%A3%85%E5%8C%85"><span class="toc-number">1.0.1.3.3.</span> <span class="toc-text">下载安装包</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AE%E9%95%9C%E5%83%8F%E4%BB%93%E5%BA%93"><span class="toc-number">1.0.1.3.4.</span> <span class="toc-text">设置镜像仓库</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%9B%B4%E6%96%B0yum%E8%BD%AF%E4%BB%B6%E5%8C%85%E7%B4%A2%E5%BC%95"><span class="toc-number">1.0.1.3.5.</span> <span class="toc-text">更新yum软件包索引</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AE%89%E8%A3%85-Docker-%E5%BC%95%E6%93%8E"><span class="toc-number">1.0.1.3.6.</span> <span class="toc-text">安装 Docker 引擎</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8-Docker"><span class="toc-number">1.0.1.3.7.</span> <span class="toc-text">启动 Docker</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E8%AE%BE%E7%BD%AE%E5%BC%80%E6%9C%BA%E8%87%AA%E5%90%AF"><span class="toc-number">1.0.1.3.8.</span> <span class="toc-text">设置开机自启</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B-Docker-%E7%89%88%E6%9C%AC"><span class="toc-number">1.0.1.3.9.</span> <span class="toc-text">查看 Docker 版本</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B-Docker-%E7%B3%BB%E7%BB%9F%E4%BF%A1%E6%81%AF"><span class="toc-number">1.0.1.3.10.</span> <span class="toc-text">查看 Docker 系统信息</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#Docker-%E5%B8%AE%E5%8A%A9%E5%91%BD%E4%BB%A4"><span class="toc-number">1.0.1.3.11.</span> <span class="toc-text">Docker 帮助命令</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%B5%8B%E8%AF%95"><span class="toc-number">1.0.1.3.12.</span> <span class="toc-text">测试</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%8D%B8%E8%BD%BD-Docker-%E5%BC%95%E6%93%8E"><span class="toc-number">1.0.1.3.13.</span> <span class="toc-text">卸载 Docker 引擎</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E9%85%8D%E7%BD%AE%E9%98%BF%E9%87%8C%E4%BA%91-%E5%AE%B9%E5%99%A8%E9%95%9C%E5%83%8F%E5%8A%A0%E9%80%9F%E5%99%A8"><span class="toc-number">1.0.1.3.14.</span> <span class="toc-text">配置阿里云 容器镜像加速器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#docker-%E6%B5%81%E7%A8%8B"><span class="toc-number">1.0.1.3.15.</span> <span class="toc-text">docker 流程</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Docker-%E5%91%BD%E4%BB%A4"><span class="toc-number">1.0.2.</span> <span class="toc-text">Docker 命令</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%95%9C%E5%83%8F%E5%91%BD%E4%BB%A4"><span class="toc-number">1.0.2.1.</span> <span class="toc-text">镜像命令</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%9F%A5%E7%9C%8B%E9%95%9C%E5%83%8F%E6%96%87%E4%BB%B6"><span class="toc-number">1.0.2.1.1.</span> <span class="toc-text">查看镜像文件</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%90%9C%E7%B4%A2%E9%95%9C%E5%83%8F"><span class="toc-number">1.0.2.1.2.</span> <span class="toc-text">搜索镜像</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%B8%8B%E8%BD%BD%E9%95%9C%E5%83%8F"><span class="toc-number">1.0.2.1.3.</span> <span class="toc-text">下载镜像</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E9%95%9C%E5%83%8F"><span class="toc-number">1.0.2.1.4.</span> <span class="toc-text">删除镜像</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%B9%E5%99%A8%E5%91%BD%E4%BB%A4"><span class="toc-number">1.0.2.2.</span> <span class="toc-text">容器命令</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%88%97%E5%87%BA%E6%89%80%E6%9C%89%E8%BF%90%E8%A1%8C%E7%9A%84%E5%AE%B9%E5%99%A8"><span class="toc-number">1.0.2.2.1.</span> <span class="toc-text">列出所有运行的容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E8%BF%9B%E5%85%A5%E5%AE%B9%E5%99%A8"><span class="toc-number">1.0.2.2.2.</span> <span class="toc-text">进入容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E9%80%80%E5%87%BA%E5%AE%B9%E5%99%A8"><span class="toc-number">1.0.2.2.3.</span> <span class="toc-text">退出容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%88%A0%E9%99%A4%E5%AE%B9%E5%99%A8"><span class="toc-number">1.0.2.2.4.</span> <span class="toc-text">删除容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8%E5%81%9C%E6%AD%A2%E5%AE%B9%E5%99%A8"><span class="toc-number">1.0.2.2.5.</span> <span class="toc-text">启动停止容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E4%BF%9D%E5%AD%98%E5%AE%B9%E5%99%A8"><span class="toc-number">1.0.2.2.6.</span> <span class="toc-text">保存容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AE%BF%E4%B8%BB%E6%9C%BA%E5%A4%8D%E5%88%B6%E5%88%B0%E5%AE%B9%E5%99%A8"><span class="toc-number">1.0.2.2.7.</span> <span class="toc-text">宿主机复制到容器</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AE%B9%E5%99%A8%E5%A4%8D%E5%88%B6%E5%88%B0%E5%AE%BF%E4%B8%BB%E6%9C%BA"><span class="toc-number">1.0.2.2.8.</span> <span class="toc-text">容器复制到宿主机</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%89%A9%E5%B1%95"><span class="toc-number">1.0.2.2.9.</span> <span class="toc-text">扩展</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8%E5%90%8E%E5%8F%B0%E8%BF%90%E8%A1%8C"><span class="toc-number">1.0.2.2.9.1.</span> <span class="toc-text">启动后台运行</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8mysqk-5-7"><span class="toc-number">1.0.2.2.9.2.</span> <span class="toc-text">启动mysqk:5.7</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8-nginx"><span class="toc-number">1.0.2.2.9.3.</span> <span class="toc-text">启动 nginx</span></a></li><li class="toc-item toc-level-6"><a class="toc-link" href="#%E5%90%AF%E5%8A%A8-Java"><span class="toc-number">1.0.2.2.9.4.</span> <span class="toc-text">启动 Java</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Docker-%E9%95%9C%E5%83%8F"><span class="toc-number">1.0.3.</span> <span class="toc-text">Docker 镜像</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AE%B9%E5%99%A8%E6%95%B0%E6%8D%AE%E5%8D%B7"><span class="toc-number">1.0.4.</span> <span class="toc-text">容器数据卷</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E5%8D%B7%E5%AE%B9%E5%99%A8"><span class="toc-number">1.0.5.</span> <span class="toc-text">数据卷容器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#DockerFile-%E6%9E%84%E5%BB%BA%E9%95%9C%E5%83%8F"><span class="toc-number">1.0.6.</span> <span class="toc-text">DockerFile 构建镜像</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%9F%BA%E7%A1%80"><span class="toc-number">1.0.6.1.</span> <span class="toc-text">基础</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%85%B3%E9%94%AE%E5%AD%97"><span class="toc-number">1.0.6.2.</span> <span class="toc-text">关键字</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%9D%E6%AD%A5%E6%9E%84%E5%BB%BA"><span class="toc-number">1.0.6.3.</span> <span class="toc-text">初步构建</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%9E%E6%88%98"><span class="toc-number">1.0.6.4.</span> <span class="toc-text">实战</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%AE%9E%E4%BE%8B"><span class="toc-number">1.0.6.5.</span> <span class="toc-text">实例</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#dockerHub-%E5%8F%91%E5%B8%83%E9%95%9C%E5%83%8F"><span class="toc-number">1.0.6.6.</span> <span class="toc-text">dockerHub 发布镜像</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%98%BF%E9%87%8C%E4%BA%91-%E5%8F%91%E5%B8%83%E9%95%9C%E5%83%8F"><span class="toc-number">1.0.6.7.</span> <span class="toc-text">阿里云 发布镜像</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%8F%82%E8%80%83"><span class="toc-number">1.0.6.8.</span> <span class="toc-text">参考</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Docker%E7%BD%91%E7%BB%9C%E5%8E%9F%E7%90%86"><span class="toc-number">1.0.7.</span> <span class="toc-text">Docker网络原理</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#ip%E6%9F%A5%E7%9C%8B"><span class="toc-number">1.0.7.1.</span> <span class="toc-text">ip查看</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E7%BD%91%E7%BB%9C"><span class="toc-number">1.0.7.2.</span> <span class="toc-text">自定义网络</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E5%88%9B%E5%BB%BA%E4%B8%80%E4%B8%AA%E7%BD%91%E7%BB%9C"><span class="toc-number">1.0.7.2.1.</span> <span class="toc-text">自定义创建一个网络</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#IDEA%E6%95%B4%E5%90%88Docker"><span class="toc-number">1.0.8.</span> <span class="toc-text">IDEA整合Docker</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#DockerCompose-%E9%9B%86%E7%BE%A4"><span class="toc-number">1.0.9.</span> <span class="toc-text">DockerCompose 集群</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#DockerSwarm-%E9%9B%86%E7%BE%A4%E7%AE%A1%E7%90%86"><span class="toc-number">1.0.10.</span> <span class="toc-text">DockerSwarm 集群管理</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#CI-CD-Jenkins"><span class="toc-number">1.0.11.</span> <span class="toc-text">CI\CD Jenkins</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%97%AE%E9%A2%98"><span class="toc-number">1.0.12.</span> <span class="toc-text">问题</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#centos7-docker%E7%AB%AF%E5%8F%A3%E6%98%A0%E5%B0%84%E5%88%B0%E5%AE%BF%E4%B8%BB%E6%9C%BA%E5%90%8E%E5%A4%96%E7%BD%91%E6%97%A0%E6%B3%95%E8%AE%BF%E9%97%AE"><span class="toc-number">1.0.12.0.1.</span> <span class="toc-text">centos7 docker端口映射到宿主机后外网无法访问</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#dockerFile%E7%94%9F%E6%88%90%E9%95%9C%E5%83%8F%E5%90%8E%EF%BC%8C%E8%BF%90%E8%A1%8C%E5%A4%B1%E8%B4%A5"><span class="toc-number">1.0.12.0.2.</span> <span class="toc-text">dockerFile生成镜像后，运行失败</span></a></li></ol></li></ol></li></ol></li></ol></li></ol></div></div><footer><nobr><span class="text-title">©</span><span class="text-content">1970 to 2020</span></nobr><wbr><nobr><span class="text-title">ICP</span><span class="text-content">——备案号——</span></nobr><wbr><wbr><nobr>published with&nbsp;<a target="_blank" rel="noopener" href="http://hexo.io">Hexo&nbsp;</a></nobr><wbr><nobr>Theme&nbsp;<a target="_blank" rel="noopener" href="https://github.com/Yue-plus/hexo-theme-arknights">Arknight&nbsp;</a></nobr><wbr><nobr>by&nbsp;<a target="_blank" rel="noopener" href="https://github.com/Yue-plus">Yue_plus</a></nobr></footer></aside></main><canvas id="canvas-dust"></canvas><script src="/vcb/js/arknights.js"></script><script src="https://cdn.bootcdn.net/ajax/libs/highlight.js/10.1.2/highlight.min.js"></script></body></html>